package com.yvon.boot.common.validation.validator;

import cn.hutool.core.util.IdcardUtil;
import com.yvon.boot.common.validation.annotation.IdCard;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author : Yvon
 * @version : 1.0
 */
public class IdCardValidator implements ConstraintValidator<IdCard, String> {
    /**
     * Is valid boolean.
     *
     * @param value   the value
     * @param context the context
     * @return the boolean
     * @author : Yvon / 2020-04-03
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
            return null == value || IdcardUtil.isValidCard(value);
    }
}
